package ink.lovejinhu.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jinhu
 * created 2021-07-16 15:18
 */
public class Solution_0448 {
    /**
     * @param nums
     * @return
     */
    public List<Integer> findDisappearedNumbers(int[] nums) {
        int n = nums.length;  //[1,n]
        int[] ints = new int[n + 1];

        for (int i = 0; i < n; i++) {
            ints[nums[i]] = Integer.MAX_VALUE;
        }
        ArrayList<Integer> res = new ArrayList<>();
        for (int i = 1; i < n + 1; i++) {
            if (ints[i] != Integer.MAX_VALUE) res.add(i);
        }

        return res;
    }

    public static void main(String[] args) {
        Solution_0448 solution_0448 = new Solution_0448();
        int[] nums = {4, 3, 2, 7, 8, 2, 3, 1};
    }

    /**
     * 原始数组：[4,3,2,7,8,2,3,1]
     * <p>
     * 重置后为：[-4,-3,-2,-7,8,2,-3,-1]
     *
     * @param nums
     * @return
     */
    public List<Integer> findDisappearedNumbers1(int[] nums) {
        for (int i = 0; i < nums.length; ++i)
           // nums[Math.abs(nums[i]) - 1] = -Math.abs(nums[Math.abs(nums[i]) - 1]);
            nums[Math.abs(nums[i]) - 1] = -Math.abs(nums[Math.abs(nums[i]) - 1]);
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < nums.length; ++i) {
            if (nums[i] > 0)
                res.add(i + 1);
        }
        return res;
    }
}
